package com.ad.pet.app.account.share;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ad.pet.DaggerMainActivityCompent;
import com.ad.pet.R;
import com.ad.pet.common.structure.mvp.BasePresenter;
import com.ad.pet.common.structure.ui.activity.AppToolbarActivity;
import com.ad.pet.models.remote.account.share.ShareEndItem;
import com.ad.pet.models.remote.home.HomeMall;
import com.ad.pet.ui.SimpleDividerDecoration;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liuyixiang on 2019/9/20.
 */

public class ShareRecordActivity extends AppToolbarActivity implements ShareContracts.View{
    @BindView(R.id.tv_share_friend)
    TextView tvShareFriend;
    @BindView(R.id.view_line1)
    View viewLine1;
    @BindView(R.id.relative_share)
    RelativeLayout relativeShare;
    @BindView(R.id.tv_share_good)
    TextView tvShareGood;
    @BindView(R.id.view_line2)
    View viewLine2;
    @BindView(R.id.relative_good)
    RelativeLayout relativeGood;
    @BindView(R.id.recycler_share)
    RecyclerView recyclerShare;
    @BindView(R.id.linear_share)
    LinearLayout linearShare;
    @BindView(R.id.recycler_share_good)
    RecyclerView recyclerShareGood;
    @BindView(R.id.tv_share_number)
    TextView tvShareNumber;
    @BindView(R.id.tv_share_good_number)
    TextView tvShareGoodNumber;

    @Inject
    SharePresenter mSharePresenter;

    boolean isLeft = true;

    @Override
    protected void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        mToolbar.setTitle("我的分享");
        mStatusLayoutManager.showContent();
    }

    @Override
    protected int contentLayout() {
        return R.layout.activity_share_record_activity;
    }

    @Override
    protected void clickRetry(View v) {

    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void initData() {
        mSharePresenter.app_share_friend_data();
        isVisableLeft(isLeft);
    }

    @Override
    protected void initEvents() {
            relativeGood.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    isLeft = false;
                    mSharePresenter.app_share_product_data();
                    isVisableLeft(isLeft);
                }
            });
            relativeShare.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    isLeft = true;
                    mSharePresenter.app_share_friend_data();
                    isVisableLeft(isLeft);
                }
            });
    }

    @Override
    public void initInject() {
        DaggerMainActivityCompent.builder().applicationComponent(getApplicationComponent())

                .activityModule(getActivityModule()).build().inject(this);
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void error(String msg) {

    }

    @Override
    public void error(int code, String msg) {

    }

    @Override
    public void app_share_product_dataSuccess(ShareEndItem shareEndItem) {
        ShareItemGoodAdapter shareFrendAdapter=new ShareItemGoodAdapter(shareEndItem.getPid_list());
        recyclerShareGood.addItemDecoration(new SimpleDividerDecoration(ShareRecordActivity.this,2,R.color.bg_color));
        recyclerShareGood.setAdapter(shareFrendAdapter);
        tvShareNumber.setText(shareEndItem.getUser_total());
        tvShareGoodNumber.setText(shareEndItem.getPrice_total());
    }

    @Override
    public void app_share_friend_dataSuccess(ShareEndItem account) {
        ShareFrendAdapter shareFrendAdapter=new ShareFrendAdapter(account.getList());
        recyclerShare.addItemDecoration(new SimpleDividerDecoration(ShareRecordActivity.this,2,R.color.bg_color));
        recyclerShare.setAdapter(shareFrendAdapter);
        tvShareNumber.setText(account.getUser_total());
        tvShareGoodNumber.setText(account.getPrice_total());
    }

    @Override
    public void viewListRecordSuccess(List<HomeMall> list) {

    }


    private void  isVisableLeft(boolean isLeft){
            if (isLeft){
                viewLine1.setVisibility(View.VISIBLE);
                viewLine2.setVisibility(View.GONE);
                linearShare.setVisibility(View.VISIBLE);
                recyclerShareGood.setVisibility(View.GONE);
            }  else {
                viewLine1.setVisibility(View.GONE);
                viewLine2.setVisibility(View.VISIBLE);
                linearShare.setVisibility(View.GONE);
                recyclerShareGood.setVisibility(View.GONE);
            }
    }
}
